package com.peak.distribution.entity.agent;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;

import com.peak.distribution.enums.Constants;
import com.peak.spring.boot.api.entity.DefaultStategyEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "dis_agent_award")
@Data
@EqualsAndHashCode(callSuper=true)
public class DisAgentAward extends DefaultStategyEntity {

	private static final long serialVersionUID = Constants.DISTRIBUTION_VERSION;
	
	/** 总奖金 */
	private Integer totalAmount;
	
	/** 当日奖金 */
	private Integer dayAmount;
	
	/** 本周奖金 */
	private Integer weekAmount;
	
	/** 当月奖金 */
	private Integer monthAmount;
	
	/** 当前季度奖金 */
	private Integer quarterAmount;
	
	/** 代理 */
	private DisAgent agent;
	
	/** 代理的团队 */
	private DisAgentTeam team;
	
	/** 签名 */
	private String sign;
	
	@ManyToOne
	@JoinColumn(name = "agent_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisAgent getAgent() {
		return agent;
	}
	
	@ManyToOne
	@JoinColumn(name = "team_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisAgentTeam getTeam() {
		return team;
	}

	@Transient
	public String getSignSource() {
		String id = this.agent == null ? "null" : this.agent.getId().toString();
		String teamId = this.team == null ? "null" : this.team.getId().toString();
		return id + teamId + this.dayAmount + this.monthAmount + this.quarterAmount + this.totalAmount + this.weekAmount;
	}
	
	public void addAmount(Integer dayAmount) {
		this.dayAmount = this.dayAmount == null ? dayAmount  : this.dayAmount + dayAmount;
	}
	
	public void addTotalAmount(Integer dayAmount) {
		this.totalAmount = this.totalAmount == null ? dayAmount  : this.totalAmount + dayAmount;
	}
}
